package com.eastfair.home.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.eastfair.boot.request.PageParams;
import com.eastfair.core.base.R;
import com.eastfair.core.exception.BizException;
import com.eastfair.home.service.HomeServiceInventoryService;
import com.eastfair.projectcore.enumeration.DataIsolationSystemSceneEnum;
import com.eastfair.venuebooking.api.ServiceInventoryFeign;
import com.eastfair.venueservice.dto.*;
import com.eastfair.venueservice.vo.ServiceInventoryInFlowVO;
import com.eastfair.venueservice.vo.ServiceInventoryOutFlowVO;
import com.eastfair.venueservice.vo.ServiceInventoryVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @Author suolong
 * @Date 2022/8/9 9:44
 */

/**
 * <p>
 * 业务实现类
 * 服务分类规格
 * </p>
 *
 * @author lye
 * @date 2022-08-09
 */
@Slf4j
@Service
public class HomeServiceInventoryServiceImpl implements HomeServiceInventoryService {

    @Resource
    private ServiceInventoryFeign serviceInventoryFeign;

    @Override
    public R<Boolean> saveInFlow(ServiceInventoryInFlowDTO serviceInventoryInFlowDTO) {
        serviceInventoryInFlowDTO.setServiceProviderType(DataIsolationSystemSceneEnum.P_COMPOSITE_COURT.getCode());
        R<Boolean> booleanR = serviceInventoryFeign.saveInFlow(serviceInventoryInFlowDTO);
        if(!booleanR.getIsSuccess()){
            throw BizException.wrap(booleanR.getCode(),booleanR.getMsg());
        }
        return booleanR;
    }

    @Override
    public R<Boolean> saveOutFlow(ServiceInventoryOutFlowDTO serviceInventoryOutFlowDTO) {
        serviceInventoryOutFlowDTO.setServiceProviderType(DataIsolationSystemSceneEnum.P_COMPOSITE_COURT.getCode());

        R<Boolean> booleanR = serviceInventoryFeign.saveOutFlow(serviceInventoryOutFlowDTO);
        if(!booleanR.getIsSuccess()){
            throw BizException.wrap(booleanR.getCode(),booleanR.getMsg());
        }
        return booleanR;
    }

    @Override
    public R<Page<ServiceInventoryVO>> queryInventoryList(PageParams<ServiceInventoryQuery> serviceInventoryQuery) {
        serviceInventoryQuery.getModel().setServiceProviderType(DataIsolationSystemSceneEnum.P_COMPOSITE_COURT.getCode());

        R<Page<ServiceInventoryVO>> pageR = serviceInventoryFeign.queryInventoryList(serviceInventoryQuery);
        if(!pageR.getIsSuccess()){
            throw BizException.wrap(pageR.getCode(),pageR.getMsg());
        }
        return pageR;
    }

    @Override
    public R<Page<ServiceInventoryInFlowVO>> queryInFlowList(PageParams<ServiceInventoryInFlowQuery> serviceInventoryQuery) {
        serviceInventoryQuery.getModel().setServiceProviderType(DataIsolationSystemSceneEnum.P_COMPOSITE_COURT.getCode());

        R<Page<ServiceInventoryInFlowVO>> pageR = serviceInventoryFeign.queryInFlowList(serviceInventoryQuery);
        if(!pageR.getIsSuccess()){
            throw BizException.wrap(pageR.getCode(),pageR.getMsg());
        }
        return pageR;
    }

    @Override
    public R<Page<ServiceInventoryOutFlowVO>> queryOutFlowList(PageParams<ServiceInventoryOutFlowQuery> serviceInventoryOutFlowQuery) {
        serviceInventoryOutFlowQuery.getModel().setServiceProviderType(DataIsolationSystemSceneEnum.P_COMPOSITE_COURT.getCode());

        R<Page<ServiceInventoryOutFlowVO>> pageR = serviceInventoryFeign.queryOutFlowList(serviceInventoryOutFlowQuery);
        if(!pageR.getIsSuccess()){
            throw BizException.wrap(pageR.getCode(),pageR.getMsg());
        }
        return pageR;
    }
}
